package it.fantacalcio.struts.action.user.forum;

import java.util.ArrayList;
import java.util.List;

import it.fantacalcio.model.Argomento;
import it.fantacalcio.model.User;
import it.fantacalcio.spring.service.MyServiceFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class PrepareSearchArgomentoAction extends Action {
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		User userInSession = (User) request.getSession().getAttribute("userInSession");
		if(userInSession==null || userInSession.getAttivo().equals("NO")){
			return mapping.findForward("noninsession");
		}
		
		List<Argomento> listaArgomento = new ArrayList<Argomento>();
		try {
			listaArgomento = MyServiceFactory.getArgomentoService().list();
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("error");
		}
		request.setAttribute("listaArgomento", listaArgomento.size() == 0 ? null : listaArgomento);
		return mapping.findForward("search");
		
	}
}
